package com.nbsaas.boot.controller.common;

import com.nbsaas.boot.common.api.apis.OperationLogApi;
import com.nbsaas.boot.common.api.domain.request.OperationLogRequest;
import com.nbsaas.boot.common.api.domain.request.OperationLogSearch;
import com.nbsaas.boot.common.api.domain.response.OperationLogResponse;
import com.nbsaas.boot.common.api.domain.simple.OperationLogSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/operationLog")
public class OperationLogController {


    @Resource
    private OperationLogApi operationLogApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("operationLog")
    @PostMapping("/search")
    public PageResponse<OperationLogSimple> search(@RequestBody OperationLogSearch request) {
        return operationLogApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("operationLog")
    @PostMapping("/list")
    public ListResponse<OperationLogSimple> list(@RequestBody OperationLogSearch request) {
        return operationLogApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("operationLog")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<OperationLogResponse> create(@RequestBody @Validated(AddOperator.class) OperationLogRequest request) {
        return operationLogApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("operationLog")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<OperationLogResponse> update(@RequestBody @Validated(UpdateOperator.class) OperationLogRequest request) {
        return operationLogApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("operationLog")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) OperationLogRequest request) {
        return operationLogApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("operationLog")
    @PostMapping("/view")
    public ResponseObject<OperationLogResponse> view(@RequestBody @Validated(ViewOperator.class) OperationLogRequest request) {
        return operationLogApi.view(request);
    }
}